package com.sunwhite.herostore.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public class RedisUtil {
    /**
     * 日志对象
     */
    static private Logger log = LoggerFactory.getLogger(RedisUtil.class);
    /***
     * redis 连接池
     */
    static private JedisPool jedisPool=null;

    /**
     * 私有化构造器
     */
    private RedisUtil(){}

    /**
     * 初始化redis连接池
     */
    public static void init(){
        try {
            jedisPool = new JedisPool("119.3.228.251", 6379);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
    }

    /**
     * 获取jedis 客户端
     * @return
     */
    public static Jedis getJedis() {
        if (jedisPool==null){
            log.error("jedisPool初始化失败！");
            throw  new RuntimeException("jedisPool 初始化失败");
        }
        Jedis jedis = jedisPool.getResource();
//        jedis.auth("123456");
        return jedis;
    }


}
